<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>title</title>
	<style>
		p{font-size: 30px;}
		p span{color:green;font-size: 30px;}
		button{font-size: 36px;/* -webkit-tap-highlight-color:rgba(255,0,0,0); */border:1px solid #ccc;background:#eee;margin:40px;}
	</style>
</head>
<body>
	<p class="location"></p>
	<p class="netType"></p>
	<p class="scanCode"></p>
	<p class="translateResult"></p>
	<p class="chooseImageResult"></p>
	<p class="uploadImageResult"></p>
	<p class="downloadImageResult"></p>
	<p class="coordsConvertResult"></p>

	<button class="openMap">打开地图</button>
	<button class="hideAllNonBaseMenuItem">hideAllNonBaseMenuItem</button>
	<button class="showAllNonBaseMenuItem">showAllNonBaseMenuItem</button>
	<button class="hideMenuItems">hideMenuItems</button>
	<button class="showMenuItems">showMenuItems</button>
	<button class="hideOptionMenu">hideOptionMenu</button>
	<button class="showOptionMenu">showOptionMenu</button>
	<hr>
	<button class="scanQRCode">scanQRCode</button>
	<button class="scanQRCodeParam">scanQRCodeParam</button>
	<hr>
	<button class="startRecord">startRecord</button>
	<button class="stopRecord">stopRecord</button>
	<button class="playVoice">playVoice</button>
	<button class="pauseVoice">pauseVoice</button>
	<button class="translateVoice">translateVoice</button>
	<hr>
	<button class="chooseImage">chooseImage</button>
	<button class="uploadImage">uploadImage</button>
	<button class="downloadImage">downloadImage</button>
	<hr>
	<button class="onSearchBeacons">onSearchBeacons</button>
	<button class="stopSearchBeacons">stopSearchBeacons</button>
	<button class="close">close</button>
	<a href="absolute.html">absolute</a>
	<a href="androidamap://navi?sourceApplication=appname&amp;poiname=fangheng&amp;lat=30.1837&amp;lon=120.20162&amp;dev=1&amp;style=1">高德导航</a> 
	<hr>
	<button id="coordsConvert">高德坐标转换</button>
</body>
</html>
<!-- <script src="http://restapi.amap.com/v3/assistant/coordinate/convert?locations=116.481499,39.990475&coordsys=gps&output=xml&key=<用户的key>"></script> -->
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script>
	var json = {};
	$.ajax({
		url : 'http://api.grhao.com/server/api.do',
		dataType : 'jsonp',
		data : {
			method : 'weixin_config',
			url : document.location.href
		},
		success : function( d ){
			result = d.data,
			appId = result.appId,
			signature = result.signature,
			timestamp = result.timestamp,
			nonceStr = result.nonceStr;
			wx.config({
			    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
			    appId: appId, // 必填，公众号的唯一标识
			    timestamp : timestamp, // 必填，生成签名的时间戳
			    nonceStr: nonceStr, // 必填，生成签名的随机串
			    signature: signature,// 必填，签名，见附录1
			    jsApiList:[
				    "getLocation",
			    	"openLocation",
			    	"hideOptionMenu",
			    	"showOptionMenu",
			    	"hideMenuItems",
			    	"showMenuItems",
			    	"hideAllNonBaseMenuItem",
			    	"showAllNonBaseMenuItem",
			    	"closeWindow",
			    	"getNetworkType",
			    	"scanQRCode",

			    	"startRecord",
			    	"stopRecord",
			    	"onVoiceRecordEnd",
			    	"playVoice",
			    	"pauseVoice",
			    	"stopVoice",
			    	"onVoicePlayEnd",
			    	"uploadVoice",
			    	"downloadVoice",
			    	"translateVoice",

			    	"chooseImage",
			    	"previewImage",
			    	"uploadImage",
			    	"downloadImage"

			    ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
			});
			wx.ready(function(){ 
				wx.getLocation({
				    // type: 'wgs84',
				    type: 'gcj02',
				    success: function (res) {
				        var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
				        var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
				        var speed = res.speed; // 速度，以米/每秒计
				        var accuracy = res.accuracy; // 位置精度
				        var locationNode = document.querySelector('.location');
				        locationNode.innerHTML = '<span>纬度:</span>' + latitude +'<span>经度:</span>' + longitude + '<span>速度</span>:' + speed + '<span>位置精度:</span>' + accuracy;
				        json.longitude = longitude;
				        json.latitude = latitude;

				    },
				    cancel : function(res){
				    	// 用户不同意当前位置授权
				    	
				    }
				});
				wx.getNetworkType({
			    	success: function (res) {
			        	var networkType = res.networkType; // 返回网络类型2g，3g，4g，wifi
			        	var netTypeNode = document.querySelector('.netType');
			        	netTypeNode.innerHTML = '<span>网络类型：</span>' + networkType;
			    	},
			    	fail : function(){
			    		// 失败的回调
			    	}

				});
			});
			wx.error(function(res){ alert(JSON.stringify(res))});
		},
		error : function(){

		}
	});

	$('.openMap').bind('touchstart',function(){

		wx.openLocation({
			latitude: 30.1837, // 纬度，浮点数，范围为90 ~ -90

			longitude: 120.20162, // 经度，浮点数，范围为180 ~ -180。

			name: '休闲果吧江虹店', // 位置名

			address: '江二路57号人工智能产业园A座', // 地址详情说明

			scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大

			infoUrl: 'http://weixin.qq.com' // 在查看位置界面底部显示的超链接,可点击跳转
		})
	});

	/*
		hideAllNonBaseMenuItem
		showAllNonBaseMenuItem
		显示/隐藏 所有的非基础功能
	*/

	$('.hideAllNonBaseMenuItem').bind('touchstart',function(){
		wx.hideAllNonBaseMenuItem();
	});
	$('.showAllNonBaseMenuItem').bind('touchstart',function(){
		wx.showAllNonBaseMenuItem();
	});
	/*	
		hideMenuItems
		showMenuItems 
		显示/隐藏微信功能列表，可以指定要处理的功能

	*/
	// 批量显示 功能列表
	$('.hideMenuItems').bind('touchstart',function(){
		wx.hideMenuItems({
			menuList : [
				'menuItem:share:appMessage',
				'menuItem:readMode', // 优化阅读，阅读模式
				'menuItem:share:timeline', // 分享朋友圈
				'menuItem:copyUrl', // 复制链接
				'menuItem:share:qq', // 分享qq朋友
				'menuItem:openWithSafari', // safari
				'menuItem:share:QZone', // qq空间
			],
			success : function(res){

			},
			fail : function(res){

			}
		});
	});
	$('.showMenuItems').bind('touchstart',function(){
		wx.hideMenuItems({
			menuList : [
				'menuItem:share:appMessage',
				'menuItem:readMode', // 优化阅读，阅读模式
				'menuItem:share:timeline', // 分享朋友圈
				'menuItem:copyUrl', // 复制链接
				'menuItem:share:qq', // 分享qq朋友
				'menuItem:openWithSafari', // safari
				'menuItem:share:QZone', // qq空间
			],
			success : function(res){},
			fail : function(res){}
		});
	});

	$('.hideOptionMenu').bind('touchstart',function(){
		wx.hideOptionMenu();
	});
	$('.showOptionMenu').bind('touchstart',function(){
		wx.showOptionMenu();
	});
	$('.close').bind('touchstart',function(){
		wx.closeWindow();
	});

	// 微信扫一扫
	$('.scanQRCode').bind('touchstart',function(){
		wx.scanQRCode();
	});
	$('.scanQRCode').bind('touchstart',function(){
		wx.scanQRCode();
	});
	$('.scanQRCodeParam').bind('touchstart',function(){
		wx.scanQRCode({
			needResult: 1,  // 默认为0，扫描结果由微信处理，1则直接返回扫描结果
			// scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
			// desc: 'scanQRCode desc',
			success: function (res) {
				$('.scanCode').html(res.resultStr);
				alert(JSON.stringify(res));
			}
		});
	});

	$('.startRecord').bind('touchstart',function(){
		wx.startRecord({
			success : function( e ){
				// alert(JSON.stringify(e))
			},
	      	cancel: function () {
	        	alert('用户拒绝授权录音');
	      	}
	    });
	});
	var voiceId = {};
	$('.stopRecord').bind('touchstart',function(){
		wx.stopRecord({
			success: function (res) {
		       voiceId.localId = res.localId;
		       alert(JSON.stringify(res.localId))
			},
		    fail: function (res) {
		       alert(JSON.stringify(res));
		    }
		});
	});

	$('.playVoice').bind('touchstart',function(){
		wx.playVoice({
		    localId: voiceId.localId // 需要播放的音频的本地ID，由stopRecord接口获得
		});
	});
	$('.pauseVoice').bind('pauseVoice',function(){
		wx.pauseVoice({
		    localId: voiceId.localId // 需要暂停的音频的本地ID，由stopRecord接口获得
		});
	});
	$('.stopVoice').bind('stopVoice',function(){
		wx.stopVoice({
		    localId: voiceId.localId // 需要停止的音频的本地ID，由stopRecord接口获得
		});
	});

	$('.translateVoice').bind('touchstart',function(){
		wx.translateVoice({
		   	localId: voiceId.localId, // 需要识别的音频的本地Id，由录音相关接口获得
		    isShowProgressTips: 1, // 默认为1，显示进度提示
		    success: function (res) {
		    	$('.translateResult').html(res.translateResult);// 语音识别的结果
		    }
		});
	});

	var imgs;

	$('.chooseImage').bind('touchstart',function(){
		wx.chooseImage({
		    success: function (res) {
		    	var html = '';
		    	imgs = res.localIds; 
		       	res.localIds.forEach(item => {
		       		html += ''+item+'<img src="' + item + '" alt="" />';
		       	});
		       	$('.chooseImageResult').html( html );
		    }
		});
	});

	$('.chooseImageResult').on('touchstart','img',function(){
		var cur = $(this).attr('src');
		wx.previewImage({
			current : cur,
			urls : imgs
		});
	});
	var serverIdArr = [];
	var dfd = $.Deferred();

	$('.uploadImage').bind('touchstart',function(){
		var len = imgs.length;
		var serverId;
		var i = 0;
		var upload = function (){
			wx.uploadImage({
				localId : imgs[i],
				success( res ){
					serverIdArr.push(res);
					i++;
					if (i < len) {
	            		upload();
	          		}else{
	          			dfd.resolve();
	          		}
				},
				fail( res ){
					alert(JSON.stringify(res));
				}
			});
		};
		upload();

	});

	dfd.done(function(){
		$('.uploadImageResult').html( JSON.stringify( serverIdArr ) + '-> done');
	});

	$('.downloadImage').bind('touchstart',function(){
	    wx.downloadImage({
	       serverId: serverIdArr[0].serverId,
	       success: function (res) {
	        	$('.downloadImageResult').html(JSON.stringify(res));
	       	}
	    });
	});

	$('#coordsConvert').click(function(){
		var str = json.longitude + ',' + json.latitude;

		$.get('http://restapi.amap.com/v3/assistant/coordinate/convert',{
			key : 'ee812e558a8c712b69b184b782fe8e48',
			locations : str,
			coordsys : 'gps',
			output : 'json',

		},function(response,status,xhr){
			$('.coordsConvertResult').html( JSON.stringify( response ));
		});
	});
	document.addEventListener('WeixinJSBridgeReady', function onBridgeReady( e ) {
		// alert(123456)

		WeixinJSBridge.on('menu:share:appmessage', function(argv){ alert("发送给好友"); });
		// alert(JSON.stringify(e));
	    // 通过下面这个API隐藏右上角按钮
	    // WeixinJSBridge.call('hideOptionMenu');
	});
	// function sendMessage(){
	//  	WeixinJSBridge.on('menu:share:appmessage', function(argv){ 
	//  		alert("发送给好友"); 
	//  	});
	// }
	// WeixinJSBridge.invoke('sendMessage',{
	//     "appid":"",                                              //appid 设置空就好了。
	//     "img_url":  'http://img.alicdn.com/tps/i4/TB161pojsnI8KJjSspewu3wIpXa.png_1080x1800Q50s50.jpg',                                   //分享时所带的图片路径
	//     "img_width": "120",                            //图片宽度
	//     "img_height": "120",                            //图片高度
	//     "link":'https://pages.tmall.com/wow/chaoshi/act/xtls-hd?spm=a3204.7084713.1997320513.2.N3gcDy&t=tlsmj&pos=1&acm=201505201.1003.2.2729368&scm=1003.2.201505201.OTHER_1515330554894_2729368',                                               //分享附带链接地址
	//     "desc":"我是一个介绍",                            //分享内容介绍
	//     "title":"标题，再简单不过了。"
	// }, function( res ){/*** 回调函数，最好设置为空 ***/});
	//var imgUrl=encodeURI("http://images.51vv.com/upload/sod/artist/mobile/W/五月天/五月天2.jpg");//分享的图片
	var imgUrl = encodeURI("http://images.51vv.com/upload/sod/artist/photos/14/08/1408343949131.jpg");

	var lineLink =document.URL;
	var descContent = '分享概况';
	var shareTitle ='分享标题';
	var appid = '';

	













	
	






	




</script>